import { createApp } from 'vue'
import { createPinia } from 'pinia'
import persist from 'pinia-plugin-persistedstate'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import {initDynamicRoutes} from "@/router/dynamicRoutes.ts";
// import "@/styles/custom-theme.css"


async function initApp() {
  // 初始化动态路由
  await initDynamicRoutes(router);
  // 创建并挂载应用
  const app = createApp(App)
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
  app.use(createPinia().use(persist))

  app.use(router)
  app.use(ElementPlus, {
    locale: zhCn,
  })

  app.mount('#app')
}

initApp().catch(error => {
  console.error('Failed to initialize app:', error);
});
